<html>
<head>
    <title>qCoreErrorTester</title>
    <script>imagePath='../images/';wrroot='../';contextPath='../';bDebug=true</script>
    <script src="../qCore.js"></script>
    <script src="../qBase.js"></script>
    <style>
    </style>
    <script>
        bDebug=true
        function bodyLoaded(){

            
//            testBasicError()

//alert("isError = "+isError("[object Error]"))

//            debug_tester()


            doBasicExceptionThreadDump()
            
//            doNoQErrTest()
            
//            ieThrowTest_simple()
            
//            ieThrowTest_complex()
            
//            qCoreErr("TEST", new Error("hi"), {var1:"val1"})
            
            
        }
        
        function debug_tester() {
            try {
                var
                     sStr="_string_"
                    ,fFunc=function _test(){doSomething()}
                    ,aArr=["v1","v2","v3"]
                    ,jJson={v1:"val1",v2:"val2"}
                ;
                debug(jJson)
            } catch(e1){qErr(e1)}
        }
        
        function doNoQErrTest(){
            bla   
        }
        
        
        function testBasicError(){
            q$.__qErrorLastErr= {msg: "bla"}
            
//pc(
//    "\n stack:\n"+s$.pad(getStackTrace())
//);
//return
            
            try {
                throw new Error("DOHH!")
            } catch(e1){
                try {
                    qErr("DOHH2!", e1)
                } catch(e2){
//alert("Throw Stack = "+q$.getThrowStackInfo(e2))
                    qErr("DOHH3!", e2)
                }
            }
        }
//        
     
        function doBasicExceptionThreadDump(){
            try {
                s1("v1", "v2", "v3")
            } catch(x){
                qErr(x)
//                debugErr(x)
//                throw x
//                q$.clearLastError()
//                throw x
                
//                var dd = debugDump(x)
//                
//                alert(dd.toString(QOpt({sectType: "alert", addCR: true})))
//alert("Throw Stack = "+x.getThrowStackInfo())
            }
        }
        
        function s1(v1, v2, v3)  {
            try {
                s2(v1, v2, v3);
            } catch (e){
                qErr( "s1 Err Msg" ,e ,{ traces  :["(s1) Trace 1", "(s1) Trace 2"] } );
            }
        }
    
        function s2(v1, v2, v3)  {
            try {
                s3(v1, v2, v3);
            } catch (e){
                qErr("s2 Err Msg", e, {traces :["(s2) Trace 1", "(s2) Trace 2"]});
            }
        }
    
        function s3(v1, v2, v3)  {
            try {
                s4(v1, v2, v3);
            } catch (e){
                qErr("s3 qErr Msg", e, {
                     traces      :["(s3) Trace 1", "(s3) Trace 2"]
                    ,varDump    :{
                             T3_NAME1 :"T3_VALUE1"
                            ,T3_NAME2 :"T3_VALUE2"
                    }
                });
            }
        }
    
        function s4(v1, v2, v3)  {
            try {
                blablabla
            } catch (e){
                qErr("s4 qErr Msg", e, {traces :["(s4) Trace 1", "(s4) Trace 2"]});
            }
    
        }
        
       /* Other Tests */
        function ieThrowTest_simple() {
            try {
                throw new Error("Testing 123");
            } catch(e1){
                    throw e1
            }
        }
      /* Complex Throw Test 
         . This example illustrates how it should NOT be done
         . The original error information is lost if the 
         . error gets to window_onerror
         . The idea of qErr is that the error is stored in a global varaible for
         . retrieval from window_onerror
      */
        function ieThrowTest_complex() {
            try {
                throw new Error("Testing 123");
            } catch(e1){
                try {
                    throw e1
                } catch(e2){
                    ieThrowTest_complexP2(2)
                }
            }
        }
        function ieThrowTest_complexP2(e1) {
            try {
                throw e1
            } catch(e2){
                try {
                    throw e2
                } catch(e3){
                    throw e3
                }
            }
        }
        
        
        
    </script>
</head>

<body>

    	<script>
            _SCR_START=" bodyLoaded();"
            bConsole=true
	        function __start() {try{
	            if(bConsole){
	                startCons({cb:true, w: 600, h: 1000})
	                _w.consoleLoaded = function consoleLoaded(){ setTimeout(_SCR_START,50) }
	            }else
	                eval(_SCR_START)
	        }catch(e){debugErr(e)}};__start()
	    </script>
</body>
</html>